package com.qf.service.Impl;

import com.qf.mapper.GuanzhuMapper;
import com.qf.pojo.Guanzhu;
import com.qf.pojo.Lianhe;
import com.qf.service.GuanZhuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GuanZhuServiceImpl implements GuanZhuService {

    @Autowired
    private GuanzhuMapper guanzhuMapper;

    //根据用户id和商品id查询判断,如果有删除,如果没有添加
    @Override
    public Boolean selectByLidAndId(Guanzhu guanzhu) {
        Guanzhu guanzhu1 = guanzhuMapper.selectByLidAndId(guanzhu);
        if (guanzhu1==null){
            insertByLidAndId(guanzhu);
            return true;
        }else {
            deleteByLidAndId(guanzhu1);
            return false;
        }
    }
    //将商品id和用户id添加到关注中
    @Override
    public void insertByLidAndId(Guanzhu guanzhu) {
        guanzhuMapper.insertLidAndId(guanzhu);
    }

    //根据商品id和用户id删除关注表信息
    @Override
    public void deleteByLidAndId(Guanzhu guanzhu) {
        guanzhuMapper.deleteByLidAndId(guanzhu);
    }

    //根据用户id查询关注表信息
    @Override
    public List<Lianhe> selectById(Integer id) {
        return guanzhuMapper.selectById(id);
    }
}

